<include file="common:header"/>
<div id="header">
    <div class="header">
        <h1 class="tit">{$site_title}</h1>
    </div>
</div>
<div class="banx-a">
    <div class="first">
        <div class="first-z">
            <if condition="$avatar neq ''">
                <img src="{$avatar}">
                <else/>
                <img src="__PUBLIC__/images/default.png">
            </if>
            <div class="zizi">
                <p>{$agent_name|cut_str='8',###}</p>
                <p>{$rank_names}</p>
            </div>
            <p class="firp">
                <a href="{:U('Agent/agent_upgrade')}">升级审核</a>
                <a href="{:U('Agent/agent_add')}">添加代理</a>
            </p>
        </div>
    </div>

    <div class="two">
        <if condition="$subAgents neq null">
            <ul id="dataList">
                <foreach name="subAgents" item="agent">
                    <li>
                    	<a href="{:U('Agent/agent_view' ,array('id' => $agent['agent_id']))}">
                    		<div class="agent_head fleft">
								<if condition="$agent['avatar'] neq ''">
	                                <img src="{$agent['avatar']}">
	                                <else/>
	                                <img src="__PUBLIC__/images/default.png">
	                            </if>
	                    	</div>
	                    	<div class="agent_msg fright">
	                    		<p>
                                    <notempty name="agent['sub_ranks_name']">
	                    			<span class="agent_rank fleft">
	                    				{$agent['agent_name']}({$agent['sub_ranks_name']})
	                    			</span>
                                        <else/>
                                        <span class="agent_rank fleft">
	                    				{$agent['agent_name']}
	                    			</span>
                                    </notempty>
                                    <span class="fright">
                                        <if condition="$agent['reg_time'] eq ''">
                                            未注册
                                            <else/>
                                            已注册
                                        </if>
                                    </span>
                                </p>
	                    		<p class="amt_p">
	                    			<span>总销售：{$agent['all_achi']}</span>
	                    			<span class="fright">余额：{$agent['money']}</span>
	                    		</p>
	                    	</div>
                    	</a>
                    </li>
                </foreach>
            </ul>
            <else/>
            <div class="no_data">
                <img src="{:C('__STATIC__')}{$theme}/Static/img/no_data.png" class="tip_img"/>
                <p class="tip_txt">暂时没有下级代理信息</p>
            </div>
        </if>
    </div>
</div>
<div class="dropload-load" id="loading" style="display: none;"><span class="loading"></span>加载中...</div>

<link rel="stylesheet" href="{:C('__STATIC__')}{$theme}/Static/{:C('css')}/dllb.css" />
<include file="common:footer"/>
<script type="text/javascript">

        /*设置列表数据*/
        function setListData(data){
            var listDom = document.getElementById("dataList");
            for (var i = 0; i < data.length; i++) {
                var pd = data[i];

                console.log( pd.avatar );
                var str = '<li>';
                str += '<a href="{:U('Agent/agent_view')}&id='+ pd.agent_id+ '">';
                str += '<div class="agent_head fleft">';
                if(pd.avatar){
                    str += "<img src='" + pd.avatar +"'>";
                }else{
                    str += "<img src='__PUBLIC__/images/default.png'>";
                }
	            str += '</div>';
	            str += '<div class="agent_msg fright">';
	            str += '<p>';
	            str += '<span class="agent_rank fleft">' + pd.agent_name + '(' + pd.sub_ranks_name + ')</span>';
	            str += '<span class="fright">';
	            if(pd.reg_time == null){
                    str += "未注册";
                }else{
                    str += "已注册";
                }
                str += '</span></p>';
                str += '<p class="amt_p">';
                str += '<span>总销售：' + pd.all_achi + '</span>';
                str += '<span class="fright">余额：' + pd.money + '</span></p></div>';
                str += '</a>';
                str += '</li>';

                var liDom = document.createElement("li");
                liDom.innerHTML = str;
                listDom.appendChild(liDom);//加在列表的后面,上拉加载
            }
        }

        var before_request = 1; // 上一次请求是否已经有返回来, 有才可以进行下一次请求
        var page = 1;
        function ajax_sourch_submit(){
            if(before_request == 0)// 上一次请求没回来 不进行下一次请求
                return false;
            before_request = 0;
            page ++;
            $.ajax({
                url:"{:U('Agent/get_more')}",
                type: "post",
                data: {
                    params: "{$params}",
                    page:page
                },
                success: function(data) {
                    $('#loading').show();
                    setTimeout(function(){
                        if(data){
                            setListData(data);
                            before_request = 1;
                        }else{
                            $("#loading").text("亲没有更多的数据了！");
                            $("#loading").show();
                        }
                    }, 700);
                }
            });
        }

</script>
